package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Restaurant;
import com.tour.service.impl.RestaurantServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-03-30
 */
@RestController
@Api(tags = "餐厅管理")
public class RestaurantController {

    @Autowired
    RestaurantServiceImpl restaurantService;

    @ApiOperation("增加餐厅")
    @PostMapping("/addRestaurant")
    public ResponseWrapper addRestaurant(@RequestBody Restaurant restaurant){
        ResponseWrapper wrapper = restaurantService.addRestaurant(restaurant);
        return wrapper;
    }

    @ApiOperation("删除餐厅")
    @DeleteMapping("/deleteRestaurant")
    @ApiImplicitParam(name="rid",value = "餐厅id")
    public ResponseWrapper deleteRestaurant(Integer rid){
        ResponseWrapper wrapper = restaurantService.deleteRestaurant(rid);
        return wrapper;
    }

    @ApiOperation("修改某个餐厅")
    @PutMapping("/updateRestaurant")
    public ResponseWrapper updateRestaurant(@RequestBody Restaurant restaurant){
        ResponseWrapper wrapper = restaurantService.updateRestaurant(restaurant);
        return wrapper;
    }

    @ApiOperation("查看所有餐厅或者模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "name",value = "餐厅名字"),
            @ApiImplicitParam(name = "city",value = "城市")
    })
    @GetMapping("/app/findAllRestaurant")
    public ResponseWrapper findRestaurant(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                          @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                          @RequestParam(name = "name",required = false)String name,
                                          @RequestParam(name = "city",required = false)String city){
        ResponseWrapper wrapper = restaurantService.findAllRestaurant(name,pageSize,pageNum,city);
        return wrapper;
    }

    @ApiOperation("查询某个餐厅")
    @GetMapping("/app/getRestBysId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "评论每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "评论页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "rid",value = "餐厅id"),
            @ApiImplicitParam(name = "foodpageSize",value = "美食每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "foodpageNum",value = "美食页码数",defaultValue = "1"),
    })
    public ResponseWrapper getRestBysId(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(name = "rid")Integer rid,
                                       @RequestParam(name = "foodpageSize",defaultValue = "10")Integer foodpageSize,
                                       @RequestParam(name = "foodpageNum",defaultValue = "1")Integer foodpageNum){
        ResponseWrapper wrapper = restaurantService.getRestBysId(rid,pageSize,pageNum,foodpageSize,foodpageNum);
        return wrapper;
    }

}

